/**
 * Created by meiguizhinian on 2018/7/10
 * Copyright © 2018 lixiaolong. All rights reserved.
 */

//TODO：等待完成
//单例/全静态/枚举
jssupport.StringHelper = {
	count_all : function (ret, string, ignore="") {
		if (ignore.length===0) {
			for (let i=0; i!==string.length; ++i) {
				let ch = string[i];
				if (!ret[ch]) {
					ret[ch] = 0;
				}
				++ret[ch];
			}
		} else {
			for (let i=0; i!==string.length; ++i) {
				let ch = string[i];
				if (ignore.indexOf(ch)!==-1) {
					continue;
				}
				if (!ret[ch]) {
					ret[ch] = 0;
				}
				++ret[ch];
			}
		}

	},

	find_all : function (ret, string, sub, maxFind=0) {
		if (maxFind===0) {
			maxFind = Number.MAX_SAFE_INTEGER;
		}
		let p = string.indexOf(sub);
		while (p!==-1) {
			ret.push(p);
			--maxFind;
			if (maxFind===0) {
				break;
			}
			p = string.indexOf(sub, p+1);
		}
	}
};
